<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
	<th:block th:include="include :: header('修改婚庆公司')" />
</head>
<body class="white-bg">
	<div class="wrapper wrapper-content animated fadeInRight ibox-content">
		<form class="form-horizontal m" id="form-company-edit" th:object="${company}">
			<input id="companyId" name="companyId" type="hidden" th:field="*{companyId}"/>
			<div class="form-group">
				<label class="col-sm-3 control-label">公司名称：</label>
				<div class="col-sm-8">
					<input class="form-control" type="text" name="companyName" id="companyName" th:field="*{companyName}" required>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label ">法人姓名：</label>
				<div class="col-sm-8">
					<input class="form-control" type="text" name="companyBoss" id="companyBoss" th:field="*{companyBoss}" required>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">原密码：</label>
				<div class="col-sm-8">
					<input id="beforePassword" name="beforePassword" class="form-control" type="password">
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">修改密码：</label>
				<div class="col-sm-8">
					<input id="newPassword" name="newPassword" class="form-control" type="password">
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">确认密码：</label>
				<div class="col-sm-8">
					<input id="confirmPassword" name="confirmPassword" class="form-control" type="password">
					<span class="help-block m-b-none"><i class="fa fa-info-circle"></i> 请再次输入您的密码</span>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label ">手机号：</label>
				<div class="col-sm-8">
					<input class="form-control" type="text" name="companyPhone" id="companyPhone"  th:field="*{companyPhone}" required>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">邮箱：</label>
				<div class="col-sm-8">
					<input class="form-control" type="text" name="companyEmail" id="companyEmail" th:field="*{companyEmail}" required>
				</div>
			</div>
		</form>
	</div>

	<th:block th:include="include :: footer" />
	<script type="text/javascript">
		var prefix = ctx + "user/company";
		var icon = "<i class='fa fa-times-circle'></i> ";
		$("#form-company-edit").validate({
			onkeyup: false,
			rules:{
				newPassword: {
					required: true,
					minlength: 5
				},
				confirmPassword: {
					required: true,
					minlength: 5,
					equalTo: "#newPassword"
				},
				companyPhone:{
					remote: {
						url: prefix +"/checkPhone",
						type: "post",
						dataType: "json",
						data: {
							"hostPhone" : function() {
								return $.common.trim($("#companyPhone").val());
							}
						},
						dataFilter: function(data, type) {
							return $.validate.unique(data);
						}
					}
				},

				beforePassword:{
					remote: {
						url: prefix +"/checkPassword",
						type: "post",
						dataType: "json",
						data: {
							"beforePassword" : function() {
								return $.common.trim($("#beforePassword").val());
							},
							"companyId" : function() {
								return $.common.trim($("#companyId").val());
							}
						},
						dataFilter: function(data, type) {
							return $.validate.unique(data);
						}
					}
				},
				companyEmail:{
					remote: {
						url: prefix +"/checkEmail",
						type: "post",
						dataType: "json",
						data: {
							"hostEmail" : function() {
								return $.common.trim($("#companyEmail").val());
							}
						},
						dataFilter: function(data, type) {
							return $.validate.unique(data);
						}
					}
				},
			},
			messages: {
				newPassword: {
					required: icon + "请输入您的密码",
					minlength: icon + "密码必须5个字符以上"
				},
				confirmPassword: {
					required: icon + "请再次输入密码",
					minlength: icon + "密码必须5个字符以上",
					equalTo: icon + "两次输入的密码不一致"
				},
				"companyPhone": {
					remote: "手机号已经存在"
				},
				"companyEmail": {
					remote: "邮箱已经存在"
				},
				"beforePassword": {
					remote: "密码不存在"
				}
			},
		    focusCleanup: true
		});
		
		function submitHandler() {
	        if ($.validate.form()) {
	        	$.operate.save(prefix + "/edit", $('#form-company-edit').serialize());
	        }
	    }

	</script>
</body>
</html>
